package com.fyx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fyx.entity.*;
import com.fyx.mapper.*;
import com.fyx.service.IPayAnalysisService;
import com.fyx.until.DateUtil;
import com.fyx.utils.RedisUtils;
import com.fyx.utils.StringUtils;
import com.mongodb.client.AggregateIterable;
import com.mongodb.client.MongoCursor;
import org.bson.Document;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.data.mongodb.core.aggregation.AggregationOptions;
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
import org.springframework.data.mongodb.core.aggregation.SkipOperation;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class PayAnalysisServiceImpl extends ServiceImpl<SysDictDetailMapper, SysDictDetail>  implements IPayAnalysisService {
    @Autowired
    private MongoTemplate mongoTemplate;

    @Autowired
    private RedisUtils redisUtils;

    @Autowired
    private ChargeDataMapper chargeDataMapper;

    @Override
    public Map charge(ChargeData chargeData, Pageable pageable) {
        Page<ChargeData> page = new Page<>(pageable.getPageNumber()+1,pageable.getPageSize());
        QueryWrapper<ChargeData> wrapper =new QueryWrapper<>();
        if(chargeData.getChannel()!=null){
            wrapper.eq("channel",chargeData.getChannel());
        }
        if(chargeData.getChargename()!=null){
            wrapper.eq("chargename",chargeData.getChargename());
        }

        IPage<ChargeData> ipage = null;

        if(redisUtils.hasKey("charge_data")){
            ipage= chargeDataMapper.selectPage(page,wrapper);
        }else{
            SimpleDateFormat ft = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss");

            long dayBeginTime =Integer.valueOf(DateUtil.date2TimeStamp(ft.format(DateUtil.getDayBegin()),"yyyy-MM-dd HH:mm:ss"));
            long dayEndTime =Integer.valueOf(DateUtil.date2TimeStamp(ft.format(DateUtil.getDayEnd()),"yyyy-MM-dd HH:mm:ss"));
            //今日
            Document sub_match = new Document();
            sub_match.put("day", new Document("$gte", dayBeginTime).append("$lte", dayEndTime));
            Document match = new Document("$match", sub_match);
            List<Document> aggregateList = new ArrayList<Document>();
            aggregateList.add(match);
            AggregateIterable<Document> todayGoodsOverview =  mongoTemplate.getCollection("charge_overview").aggregate(aggregateList);
            MongoCursor<Document> iterator = todayGoodsOverview.iterator();
            List<ChargeData> list1 = new ArrayList<>();
            while (iterator.hasNext()) {
                Map mapList = iterator.next();
                String channel="";
                if(!mapList.isEmpty()){
                    channel = mapList.get("channel")+"";}
                if(!channel.equals("true")){
                for (Object key : mapList.keySet()) {
                    String mapKey = (String) key;
                    if (!mapKey.equals("_id") && !mapKey.equals("day") && !mapKey.equals("channel")) {
                        ChargeData chargeDataEntity1 = new ChargeData();
                        chargeDataEntity1.setChannel(channel);
                        chargeDataEntity1.setChargename(mapKey);
                        String ChargeValue = mapList.get(mapKey) + "";
                        chargeDataEntity1.setChargevalue(ChargeValue);
                        list1.add(chargeDataEntity1);
                    }
                }}

            }
            iterator.close();

            long yesterdayBeginTime =dayBeginTime-24*3600;
            long yesterdayEndTime =dayEndTime-24*3600;
            //昨日
            sub_match = new Document();
            sub_match.put("day", new Document("$gte", yesterdayBeginTime).append("$lte", yesterdayEndTime));
            match = new Document("$match", sub_match);
            aggregateList = new ArrayList<Document>();
            aggregateList.add(match);
            AggregateIterable<Document> yesterdayGoodsOverview =  mongoTemplate.getCollection("charge_overview").aggregate(aggregateList);
            iterator = yesterdayGoodsOverview.iterator();
            List<ChargeData> list2 = new ArrayList<>();
            while (iterator.hasNext()) {
                Map mapList = iterator.next();
                String channel="";
                if(!mapList.isEmpty()){
                channel = mapList.get("channel")+"";}
                if(!channel.equals("true")){
                for (Object key : mapList.keySet()) {
                    String mapKey = (String) key;
                    if(!mapKey.equals("_id") && !mapKey.equals("day") && !mapKey.equals("channel")){
                        ChargeData chargeDataEntity2 = new ChargeData();
                        chargeDataEntity2.setChannel(channel);
                        chargeDataEntity2.setChargename(mapKey);
                        String ChargeValue= mapList.get(mapKey)+"";
                        chargeDataEntity2.setChargevalue1(ChargeValue);
                        list2.add(chargeDataEntity2);
                    }
                }}
            }
            iterator.close();
            long beforeYesterdayBeginTime =dayBeginTime-2*24*3600;
            long beforeYesterdayEndTime =dayEndTime-2*24*3600;
            sub_match = new Document();
            sub_match.put("day", new Document("$gte", beforeYesterdayBeginTime).append("$lte", beforeYesterdayEndTime));
            match = new Document("$match", sub_match);
            aggregateList = new ArrayList<Document>();
            aggregateList.add(match);
            AggregateIterable<Document> beforeYesterdayGoodsOverview =  mongoTemplate.getCollection("charge_overview").aggregate(aggregateList);
            iterator = beforeYesterdayGoodsOverview.iterator();
            List<ChargeData> list3 = new ArrayList<>();
            while (iterator.hasNext()) {
                Map mapList = iterator.next();
                String channel =  mapList.get("channel")+"";
                if(!channel.equals("true")){
                for (Object key : mapList.keySet()) {
                    String mapKey = (String) key;
                    if(!mapKey.equals("_id") && !mapKey.equals("day") && !mapKey.equals("channel")){
                        ChargeData chargeDataEntity3 = new ChargeData();
                        chargeDataEntity3.setChannel(channel);
                        chargeDataEntity3.setChargename(mapKey);
                        String ChargeValue= mapList.get(mapKey)+"";
                        chargeDataEntity3.setChargevalue2(ChargeValue);
                        list3.add(chargeDataEntity3);
                    }
                }}
            }
            iterator.close();
            List<ChargeData> list = new ArrayList<>();
            list.addAll(list1);
            list.addAll(list2);
            list.addAll(list3);
            //去重
            for( int  i  =   0 ; i  <  list.size()  -   1 ; i ++ )  {
                for( int  j  =  list.size()  -   1 ; j  >  i; j -- )  {
                    ChargeData chargeDataEntity1 = list.get(i);
                    ChargeData chargeDataEntity2 = list.get(j);
                    if( chargeDataEntity1.getChannel().equals(chargeDataEntity2.getChannel())&& chargeDataEntity1.getChargename().equals(chargeDataEntity2.getChargename())) {
                        if(StringUtils.isBlank(chargeDataEntity1.getChargevalue())){
                            chargeDataEntity1.setChargevalue(chargeDataEntity2.getChargevalue());
                        }
                        if(StringUtils.isBlank(chargeDataEntity1.getChargevalue1())){
                            chargeDataEntity1.setChargevalue1(chargeDataEntity2.getChargevalue1());
                        }
                        if(StringUtils.isBlank(chargeDataEntity1.getChargevalue2())){
                            chargeDataEntity1.setChargevalue2(chargeDataEntity2.getChargevalue2());
                        }
                        list.remove(j);
                    }
                }
            }
            if(list.size()>0){
                chargeDataMapper.delete(new QueryWrapper<>());
                chargeDataMapper.insertBatch(list);
            }
            ipage = chargeDataMapper.selectPage(page,wrapper);
            redisUtils.set("charge_data",ipage.getRecords(),600);
        }

        List<ChargeData> chargeDatalist = ipage.getRecords();
        long total = ipage.getTotal();
        Map map =new HashMap();
        map.put("list",chargeDatalist);
        map.put("total",total);
        return map;
    }

    @Autowired
    private PropsDataMapper propsDataMapper;

    @Override
    public Map props(PropsData propsData, Pageable pageable) {
        Page<PropsData> page = new Page<>(pageable.getPageNumber()+1,pageable.getPageSize());
        QueryWrapper<PropsData> wrapper =new QueryWrapper<>();
        if(propsData.getChannel()!=null){
            wrapper.eq("channel",propsData.getChannel());
        }
        if(propsData.getPropsname()!=null){
            wrapper.eq("propsname",propsData.getPropsname());
        }

        IPage<PropsData> ipage = null;
        if(redisUtils.hasKey("props_data")){
            ipage = propsDataMapper.selectPage(page,wrapper);
        }else{
            SimpleDateFormat ft = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss");
            long dayBeginTime =Integer.valueOf(DateUtil.date2TimeStamp(ft.format(DateUtil.getDayBegin()),"yyyy-MM-dd HH:mm:ss"));
            long dayEndTime =Integer.valueOf(DateUtil.date2TimeStamp(ft.format(DateUtil.getDayEnd()),"yyyy-MM-dd HH:mm:ss"));
            //道具消耗
            //今日
            Document sub_match = new Document();
            sub_match.put("day", new Document("$gte", dayBeginTime).append("$lte", dayEndTime));
            Document match = new Document("$match", sub_match);
            List<Document> aggregateList = new ArrayList<Document>();
            aggregateList.add(match);
            AggregateIterable<Document> todayGoodsOverview =  mongoTemplate.getCollection("goods_overview").aggregate(aggregateList);
            MongoCursor<Document> iterator = todayGoodsOverview.iterator();
            List<PropsData> list1 = new ArrayList<>();
            while (iterator.hasNext()) {
                Map mapList = iterator.next();
                String channel = mapList.get("channel")+"";
                if(!channel.equals("true")){
                for (Object key : mapList.keySet()) {
                    String mapKey = (String) key;
                    if (!mapKey.equals("_id") && !mapKey.equals("day") && !mapKey.equals("channel")) {
                        PropsData propsDataEntity1 = new PropsData();
                        propsDataEntity1.setChannel(channel);
                        propsDataEntity1.setPropsname(mapKey);
                        String PropsValue=mapList.get(mapKey)+"";
                        propsDataEntity1.setPropsvalue(PropsValue);
                        list1.add(propsDataEntity1);
                    }
                }}
            }
            iterator.close();
            long yesterdayBeginTime =dayBeginTime-24*3600;
            long yesterdayEndTime =dayEndTime-24*3600;
            //昨日
            sub_match = new Document();
            sub_match.put("day", new Document("$gte", yesterdayBeginTime).append("$lte", yesterdayEndTime));
            match = new Document("$match", sub_match);
            aggregateList = new ArrayList<Document>();
            aggregateList.add(match);
            AggregateIterable<Document> yesterdayGoodsOverview =  mongoTemplate.getCollection("goods_overview").aggregate(aggregateList);
            iterator = yesterdayGoodsOverview.iterator();
            List<PropsData> list2 = new ArrayList<>();
            while (iterator.hasNext()) {
                Map mapList = iterator.next();
                String channel = mapList.get("channel").toString();
                if(!channel.equals("true")){
                for (Object key : mapList.keySet()) {
                    String mapKey = (String) key;
                    if(!mapKey.equals("_id") && !mapKey.equals("day") && !mapKey.equals("channel")){
                        PropsData propsDataEntity2 = new PropsData();
                        propsDataEntity2.setChannel(channel);
                        propsDataEntity2.setPropsname(mapKey);
                        String PropsValue=mapList.get(mapKey)+"";
                        propsDataEntity2.setPropsvalue1(PropsValue);
                        list1.add(propsDataEntity2);
                    }
                }}
            }
            iterator.close();
            long beforeYesterdayBeginTime =dayBeginTime-2*24*3600;
            long beforeYesterdayEndTime =dayEndTime-2*24*3600;
            sub_match = new Document();
            sub_match.put("day", new Document("$gte", beforeYesterdayBeginTime).append("$lte", beforeYesterdayEndTime));
            match = new Document("$match", sub_match);
            aggregateList = new ArrayList<Document>();
            aggregateList.add(match);
            AggregateIterable<Document> beforeYesterdayGoodsOverview =  mongoTemplate.getCollection("goods_overview").aggregate(aggregateList);
            iterator = beforeYesterdayGoodsOverview.iterator();
            List<PropsData> list3 = new ArrayList<>();
            while (iterator.hasNext()) {
                Map mapList = iterator.next();
                String channel =  mapList.get("channel")+"";
                if(!channel.equals("true")){
                for (Object key : mapList.keySet()) {
                    String mapKey = (String) key;
                    if(!mapKey.equals("_id") && !mapKey.equals("day") && !mapKey.equals("channel")){
                        PropsData propsDataEntity3 = new PropsData();
                        propsDataEntity3.setChannel(channel);
                        propsDataEntity3.setPropsname(mapKey);
                        String PropsValue=mapList.get(mapKey)+"";
                        propsDataEntity3.setPropsvalue2(PropsValue);
                        list3.add(propsDataEntity3);
                    }
                }}

            }
            iterator.close();
            List<PropsData> list = new ArrayList<>();
            list.addAll(list1);
            list.addAll(list2);
            list.addAll(list3);
            //去重
            for( int  i  =   0 ; i  <  list.size()  -   1 ; i ++ )  {
                for( int  j  =  list.size()  -   1 ; j  >  i; j -- )  {
                    PropsData propsDataEntity1 = list.get(i);
                    PropsData propsDataEntity2 = list.get(j);
                    if(propsDataEntity1.getChannel().equals(propsDataEntity2.getChannel()) && propsDataEntity1.getPropsname().equals(propsDataEntity2.getPropsname()) ) {
                        if(StringUtils.isBlank(propsDataEntity1.getPropsvalue())){
                            propsDataEntity1.setPropsvalue(propsDataEntity2.getPropsvalue());
                        }
                        if(StringUtils.isBlank(propsDataEntity1.getPropsvalue1())){
                            propsDataEntity1.setPropsvalue1(propsDataEntity2.getPropsvalue1());
                        }
                        if(StringUtils.isBlank(propsDataEntity1.getPropsvalue2())){
                            propsDataEntity1.setPropsvalue2(propsDataEntity2.getPropsvalue2());
                        }
                        list.remove(j);
                    }
                }
            }

            if(list1.size()>0){
                propsDataMapper.delete(new QueryWrapper<>());
                propsDataMapper.insertBatch(list);
            }
            ipage = propsDataMapper.selectPage(page,wrapper);
            redisUtils.set("props_data",ipage.getRecords(),600);
        }
        List<PropsData> propsDatalist = ipage.getRecords();
        long total = ipage.getTotal();
        Map map =new HashMap();
        map.put("list",propsDatalist);
        map.put("total",total);
        return map;
    }


    @Override
    public Map ranking(OrderEntity orderEntity, Pageable pageable) {
        Criteria criteria = new Criteria();
        if (orderEntity.getQTime()!=null){
            criteria.andOperator(Criteria.where("time_end").gte(orderEntity.getQTime().get(0).getTime()/1000).lte(orderEntity.getQTime().get(1).getTime()/1000));
        }else{
            criteria.andOperator(Criteria.where("time_end").gte(DateUtil.getDayBegin().getTime()/1000).lte(DateUtil.getDayEnd().getTime()/1000));
        }

        Criteria criteria1 = new Criteria();
        if(orderEntity.getAll_fee1()!=0 && orderEntity.getAll_fee2()!=0) {
            criteria1.and("all_fee").gte(orderEntity.getAll_fee1() * 100).lte(orderEntity.getAll_fee2()*100);
        }else if(orderEntity.getAll_fee2()!=0){
            criteria1.and("all_fee").gte(orderEntity.getAll_fee1()*100);
        }else if(orderEntity.getAll_fee2()!=0){
            criteria1.and("all_fee").lte(orderEntity.getAll_fee2()*100);
        }

        Aggregation aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group("pid").sum("total_fee").as("all_fee").first("pid").as("pid"),
                Aggregation.match(criteria1),
                Aggregation.lookup("user","pid","id","orderUser"),
                Aggregation.project("all_fee","pid","orderUser"),
                Aggregation.sort(Sort.Direction.DESC,new String[]{"all_fee"}),
                new SkipOperation((pageable.getPageNumber())*pageable.getPageSize()),
                Aggregation.limit(pageable.getPageSize())
        );
        AggregationResults<OrderEntity> ar = mongoTemplate.aggregate(aggregation, "order", OrderEntity.class);
        List<OrderEntity> list = ar.getMappedResults();

        aggregation = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group("pid").sum("total_fee").as("all_fee").first("pid").as("pid"),
                Aggregation.match(criteria1),
                Aggregation.group().count().as("total")
        );
        ar = mongoTemplate.aggregate(aggregation, "order", OrderEntity.class);
        long total = 0;
        if( ar.getMappedResults().size()>0){
            total= ar.getMappedResults().get(0).getTotal();
        }

        Map map =new HashMap();
        map.put("list",list);
        map.put("total",total);
        return map;
    }

    @Autowired
    private OverviewMapper overviewMapper;

    @Override
    public Map propsOverview(Overview overview, Pageable pageable) {
        Page<Overview> page = new Page<>(pageable.getPageNumber()+1,pageable.getPageSize());
        String overviewType =overview.getOverviewType();
        long time1 = 0;
        long time2 = 0;
        if(overview.getQTime()!=null){
            time1 =overview.getQTime().get(0).getTime()/1000;
            time2 =overview.getQTime().get(1).getTime()/1000;
        }

        String overviewName =overview.getOverviewName();
        IPage<Overview> ipage = overviewMapper.getOverviewList(page,overviewType,time1,time2,overviewName);
        List<Overview> list = ipage.getRecords();
        if(list.size()>0){
            for(Overview overview1:list){
                overview1.setGId(overview1.getOverviewName().split("_")[0]);
                overview1.setWay(overview1.getOverviewName().split("_")[1]);
                overview1.setResult(overview1.getOverviewName().split("_")[2]);
            }
        }
        long total = ipage.getTotal();
        Map map =new HashMap();
        map.put("list",list);
        map.put("total",total);
        return map;
    }
    @Autowired
    private CardInfoMapper cardInfoMapper;

    @Override
    public Map propsCard(CardInfoEntity cardInfoEntity, Pageable pageable){
        Page<CardInfoEntity> page = new Page<>(pageable.getPageNumber()+1,pageable.getPageSize());
        QueryWrapper<CardInfoEntity> wrapper =new QueryWrapper<>();
        if(cardInfoEntity.getQTime()!=null){
            wrapper.ge("time",cardInfoEntity.getQTime().get(0).getTime()/1000);
            wrapper.le("time",cardInfoEntity.getQTime().get(1).getTime()/1000);
        }
        if(cardInfoEntity.getChannel()!=null){
            wrapper.eq("channel",cardInfoEntity.getChannel());
        }else{
            wrapper.eq("channel","total");

        }
        wrapper.orderBy(true,false,"time");
        IPage<CardInfoEntity> ipage = cardInfoMapper.selectPage(page,wrapper);
        List<CardInfoEntity> list = ipage.getRecords();
        Map map =new HashMap();
        map.put("list",list);
        map.put("total",ipage.getTotal());
        return map;
    }



    @Autowired
    private PropsInfoMapper propsInfoMapper;

    @Override
    public Map  chargeBuyProps(PropsInfoEntity propsInfoEntity, Pageable pageable){
        Page<PropsInfoEntity> page = new Page<>(pageable.getPageNumber()+1,pageable.getPageSize());
        QueryWrapper<PropsInfoEntity> wrapper =new QueryWrapper<>();
        if(propsInfoEntity.getQTime()!=null){
            wrapper.ge("time",propsInfoEntity.getQTime().get(0).getTime()/1000);
            wrapper.le("time",propsInfoEntity.getQTime().get(1).getTime()/1000);
        }
        if(StringUtils.isNotBlank(propsInfoEntity.getChannel())){
            wrapper.eq("channel",propsInfoEntity.getChannel());
        }
        wrapper.orderByDesc("time");
        IPage<PropsInfoEntity> ipage = propsInfoMapper.selectPage(page,wrapper);
        List<PropsInfoEntity> list = ipage.getRecords();
        List<Map> list1=new ArrayList();
        String[] xData=new String[list.size()];
        Map yDataMaps = new HashMap();
        if(list.size()>0) {
            for (int i = 0; i < list.size(); i++) {
                xData[i] = DateUtil.timeStamp2Date(list.get(i).getTime() + "", "yyyy-MM-dd ").trim();
                String sad[]= list.get(i).getTheValues().split("/");
                int ewq[]=new int[98];
                if(propsInfoEntity.getChannel().equals("pamjxl_total")){
                    for (int j=0;j<sad.length;j++){
                        int s=Integer.parseInt(sad[j].split("-")[0]) ;
                        int r=Integer.parseInt(sad[j].split("-")[1]);
                        if(s==500232) {
                            ewq[0] =r;
                        }
                        else if(s>=500261&&s<=500270) {
                            ewq[1] += r;
                        }
                        else if(s>=500241&&s<=500250) {
                            ewq[2] += r;
                        }
                        else if(s>=500251&&s<=500260) {
                            ewq[3] += r;
                        }else if(s==500779||s==500789||s==500799||s==500809) {  //3
                            ewq[4] += r;
                        }else if(s==500780||s==500790||s==500800||s==500810) {  //6
                            ewq[5] += r;
                        }else if(s==500781||s==500791||s==500801||s==500811) { //12
                            ewq[6] += r;
                        }else if(s==500782||s==500792||s==500802||s==500812) {  //30
                            ewq[7] += r;
                        }else if(s==500783||s==500793||s==500803||s==500813) {  //50
                            ewq[8] += r;
                        }else if(s==500784||s==500794||s==500804||s==500814) {  //68
                            ewq[9] += r;
                        }else if(s==500785||s==500795||s==500805||s==500815) { //98
                            ewq[10] += r;
                        }else if(s==500786||s==500796||s==500806||s==500816) {  //168
                            ewq[11] += r;
                        }else if(s==500787||s==500797||s==500807||s==500817) {  //328
                            ewq[12] += r;
                        }else if(s==500788||s==500798||s==500808||s==500818) {  //648
                            ewq[13] += r;
                        }else if(s==500819||s==500829||s==500839||s==500849) {  //3
                            ewq[14] += r;
                        }else if(s==500820||s==500830||s==500840||s==500850) {
                            ewq[15] += r;
                        }else if(s==500821||s==500831||s==500841||s==500851) {
                            ewq[16] += r;
                        }else if(s==500822||s==500832||s==500842||s==500852) {
                            ewq[17] += r;
                        }else if(s==500823||s==500833||s==500843||s==500853) {
                            ewq[18] += r;
                        }else if(s==500824||s==500834||s==500844||s==500854) {
                            ewq[19] += r;
                        }else if(s==500825||s==500835||s==500845||s==500855) {
                            ewq[20] += r;
                        }else if(s==500826||s==500836||s==500846||s==500856) {
                            ewq[21] += r;
                        }else if(s==500827||s==500837||s==500847||s==500857) {
                            ewq[22] += r;
                        }else if(s==500828||s==500838||s==500848||s==500858) {
                            ewq[23] += r;
                        }else if(s==500899||s==500909||s==500919||s==500929){
                            ewq[24] += r;
                        } else if(s==500900||s==500910||s==500920||s==500930){
                            ewq[25] += r;
                        }  else if(s==500901||s==500911||s==500921||s==500931){
                            ewq[26] += r;
                        }  else if(s==500902||s==500912||s==500922||s==500932){
                            ewq[27] += r;
                        }  else if(s==500903||s==500913||s==500923||s==500933){
                            ewq[28] += r;
                        }  else if(s==500904||s==500914||s==500924||s==500934){
                            ewq[29] += r;
                        }  else if(s==500905||s==500915||s==500925||s==500935){
                            ewq[30] += r;
                        }  else if(s==500906||s==500916||s==500926||s==500936){
                            ewq[31] += r;
                        }  else if(s==500907||s==500917||s==500927||s==500937){
                            ewq[32] += r;
                        }  else if(s==500908||s==500918||s==500928||s==500938){
                            ewq[33] += r;
                        } else if(s==500332){
                            ewq[34] = r;
                        }else if(s==501000){
                            ewq[65] =r ;
                        }
                        else if(s==200089||s==500292) {
                            ewq[35] += r;
                        } else if(s==200090||s==500293) {
                            ewq[36] += r;
                        } else if(s==200091||s==500294) {
                            ewq[37] += r;
                        }else if(s==200092||s==500295) {
                            ewq[38] += r;
                        }
                        else if(s==500216||s==500611) {
                            ewq[39] += r;
                        }
                        else if(s==500217||s==500612) {
                            ewq[40] += r;
                        }
                        else if(s==500218||s==500613) {
                            ewq[41] += r;
                        }
                        else if(s==500219||s==500614) {
                            ewq[42] += r;
                        }
                        else if(s==500271) {
                            ewq[43] = r;
                        }
                        else if(s==500272) {
                            ewq[44] = r;
                        }  else if(s==500273) {
                            ewq[45] = r;
                        }  else if(s==500274) {
                            ewq[46] = r;
                        }  else if(s==500275) {
                            ewq[47] = r;
                        }  else if(s==500276) {
                            ewq[48] = r;
                        }  else if(s==500277) {
                            ewq[49] = r;
                        }  else if(s==500278) {
                            ewq[50] = r;
                        }  else if(s==500279) {
                            ewq[51] = r;
                        }  else if(s==500331) {
                            ewq[52] = r;
                        } else if(s==500330) {
                            ewq[53] = r;
                        }
                        else if(s==200167) {
                            ewq[54] = r;
                        }
                        else if(s==200170) {
                            ewq[55] = r;
                        }  else if(s==200173) {
                            ewq[56] = r;
                        }  else if(s==200176) {
                            ewq[57] = r;
                        }  else if(s==502117) {
                            ewq[58] = r;
                        }  else if(s==502118) {
                            ewq[59] = r;
                        }  else if(s==502119) {
                            ewq[60] = r;
                        }  else if(s==502128) {
                            ewq[61] = r;
                        }  else if(s==502129) {
                            ewq[62] = r;
                        } else if(s==502130) {
                            ewq[63] = r;
                        }  else if(s==200164) {
                            ewq[64] = r;
                        }else if(s==502001) {
                            ewq[66] = r;
                        } else if(s==502002) {
                            ewq[67] = r;
                        } else if(s==502003) {
                            ewq[68] = r;
                        } else if(s==502004) {
                            ewq[69] = r;
                        } else if(s==502005) {
                            ewq[70] = r;
                        } else if(s==502006) {
                            ewq[71] = r;
                        } else if(s==502007) {
                            ewq[72] = r;
                        } else if(s==502008) {
                            ewq[73] = r;
                        } else if(s==502009) {
                            ewq[74] = r;
                        } else if(s==502010) {
                            ewq[75] = r;
                        } else if(s==502100) {
                            ewq[76] = r;
                        } else if(s==502101) {
                            ewq[77] = r;
                        } else if(s==502102) {
                            ewq[78] = r;
                        } else if(s==502103) {
                            ewq[79] = r;
                        } else if(s==502104) {
                            ewq[80] = r;
                        } else if(s==502105) {
                            ewq[81] = r;
                        }else if(s==502106) {
                            ewq[82] = r;
                        } else if(s==502107) {
                            ewq[83] = r;
                        } else if(s==502108) {
                            ewq[84] = r;
                        } else if(s==502109) {
                            ewq[85] = r;
                        } else if(s==502110) {
                            ewq[86] = r;
                        } else if(s==502111) {
                            ewq[87] = r;
                        } else if(s==502112) {
                            ewq[88] = r;
                        } else if(s==502113) {
                            ewq[89] = r;
                        } else if(s==502114) {
                            ewq[90] = r;
                        }else if(s==502201||s==502203){
                            ewq[91] += r;
                        }else if(s==502206||s==502208||s==502210||s==502212||s==502215){
                            ewq[92] += r;
                        }else if(s==502207||s==502209||s==502211||s==502213||s==502216){
                            ewq[93] += r;
                        }else if(s==502217||s==502219||s==502221||s==502223||s==502226){
                            ewq[94] += r;
                        }else if(s==502218||s==502220||s==502222||s==502224||s==502227){
                            ewq[95] += r;
                        }else if(s==502228||s==502230||s==502232||s==502234||s==502237){
                            ewq[96] += r;
                        }else if(s==502229||s==502231||s==502233||s==502235||s==502238){
                            ewq[97] += r;
                        }
                    }
                }
                else{
                for (int j=0;j<sad.length;j++){
                    int s=Integer.parseInt(sad[j].split("-")[0]) ;
                    int r=Integer.parseInt(sad[j].split("-")[1]);
                    if(s==500232) {
                        ewq[0] =r;
                    }
                    else if(s>=500261&&s<=500270) {
                        ewq[1] += r;
                    }
                    else if(s>=500241&&s<=500250) {
                        ewq[2] += r;
                    }
                    else if(s>=500251&&s<=500260) {
                        ewq[3] += r;
                    }else if(s==500296||s==500297||s==500335||s==500337||s==500339||s==500354||s==500355||s==500650||s==500655||s==500665||s==500675) {
                        ewq[4] += r;
                    }else if(s==500298||s==500299||s==500338||s==500340||s==500345||s==500359||s==500405||s==500651||s==500656||s==500666||s==500676) {
                        ewq[5] += r;
                    }else if(s==500300||s==500301||s==500341||s==500346||s==500356||s==500360||s==500406||s==500652||s==500657||s==500667||s==500677) {
                        ewq[6] += r;
                    }else if(s==500302||s==500303||s==500342||s==500347||s==500357||s==500361||s==500426||s==500653||s==500658||s==500668||s==500678) {
                        ewq[7] += r;
                    }else if(s==500304||s==500305||s==500343||s==500348||s==500358||s==500362||s==500427||s==500654||s==500659||s==500669||s==500679) {
                        ewq[8] += r;
                    }else if(s==500407||s==500411||s==500428||s==500333||s==500660||s==500670||s==500680||s==500755) {
                        ewq[9] += r;
                    }else if(s==500306||s==500307||s==500344||s==500349||s==500363||s==500429||s==500661||s==500671||s==500681||s==500756) {
                        ewq[10] += r;
                    }else if(s==500308||s==500309||s==500350||s==500364||s==500408||s==500662||s==500672||s==500682||s==500757) {
                        ewq[11] += r;
                    }else if(s==500310||s==500311||s==500351||s==500365||s==500409||s==500663||s==500673||s==500683||s==500758) {
                        ewq[12] += r;
                    }else if(s==500312||s==500352||s==500410||s==500664||s==500674||s==500684||s==500759||s==502225) {
                        ewq[13] += r;
                    }else if(s==500320||s==500367||s==500369||s==500371||s==500685||s==500690||s==500700||s==500710) {
                        ewq[14] += r;
                    }else if(s==500321||s==500370||s==500372||s==500377||s==500412||s==500686||s==500691||s==500701||s==500711) {
                        ewq[15] += r;
                    }else if(s==500322||s==500373||s==500378||s==500413||s==500687||s==500692||s==500702||s==500712) {
                        ewq[16] += r;
                    }else if(s==500323||s==500374||s==500379||s==500430||s==500688||s==500693||s==500703||s==500713) {
                        ewq[17] += r;
                    }else if(s==500324||s==500375||s==500380||s==500431||s==500689||s==500694||s==500704||s==500714) {
                        ewq[18] += r;
                    }else if(s==500414||s==500418||s==500432||s==500695||s==500705||s==500715||s==500760) {
                        ewq[19] += r;
                    }else if(s==500325||s==500376||s==500381||s==500433||s==500696||s==500706||s==500716||s==500761) {
                        ewq[20] += r;
                    }else if(s==500326||s==500382||s==500415||s==500697||s==500707||s==500717||s==500762) {
                        ewq[21] += r;
                    }else if(s==500327||s==500383||s==500416||s==500698||s==500708||s==500718||s==500763) {
                        ewq[22] += r;
                    }else if(s==500328||s==500384||s==500417||s==500699||s==500709||s==500719||s==500764||s==502236) {
                        ewq[23] += r;
                    }else if(s==500619||s==500623||s==500630||s==500640){
                        ewq[24] += r;
                    } else if(s==500620||s==500624||s==500631||s==500641){
                        ewq[25] += r;
                    }  else if(s==500621||s==500625||s==500632||s==500642){
                        ewq[26] += r;
                    }  else if(s==500622||s==500626||s==500633||s==500643){
                        ewq[27] += r;
                    }  else if(s==500627||s==500634||s==500644||s==500770){
                        ewq[28] += r;
                    }  else if(s==500628||s==500635||s==500645||s==500771){
                        ewq[29] += r;
                    }  else if(s==500629||s==500636||s==500646||s==500772){
                        ewq[30] += r;
                    }  else if(s==500637||s==500647||s==500773||s==500776){
                        ewq[31] += r;
                    }  else if(s==500638||s==500648||s==500774||s==500777){
                        ewq[32] += r;
                    }  else if(s==500639||s==500649||s==500775||s==500778||s==502214){
                        ewq[33] += r;
                    } else if(s==500332){
                        ewq[34] = r;
                    }else if(s==501000){
                        ewq[65] =r ;
                    }
                    else if(s==200089||s==500292) {
                        ewq[35] += r;
                    } else if(s==200090||s==500293) {
                        ewq[36] += r;
                    } else if(s==200091||s==500294) {
                        ewq[37] += r;
                    }else if(s==200092||s==500295) {
                        ewq[38] += r;
                    }
                    else if(s==500216||s==500611) {
                        ewq[39] += r;
                    }
                    else if(s==500217||s==500612) {
                        ewq[40] += r;
                    }
                    else if(s==500218||s==500613) {
                        ewq[41] += r;
                    }
                    else if(s==500219||s==500614) {
                        ewq[42] += r;
                    }
                    else if(s==500271) {
                        ewq[43] = r;
                    }
                    else if(s==500272) {
                        ewq[44] = r;
                    }  else if(s==500273) {
                        ewq[45] = r;
                    }  else if(s==500274) {
                        ewq[46] = r;
                    }  else if(s==500275) {
                        ewq[47] = r;
                    }  else if(s==500276) {
                        ewq[48] = r;
                    }  else if(s==500277) {
                        ewq[49] = r;
                    }  else if(s==500278) {
                        ewq[50] = r;
                    }  else if(s==500279) {
                        ewq[51] = r;
                    }  else if(s==500331) {
                        ewq[52] = r;
                    } else if(s==500330) {
                        ewq[53] = r;
                    }
                    else if(s==200167) {
                        ewq[54] = r;
                    }
                    else if(s==200170) {
                        ewq[55] = r;
                    }  else if(s==200173) {
                        ewq[56] = r;
                    }  else if(s==200176) {
                        ewq[57] = r;
                    }   else if(s==502117) {
                        ewq[58] = r;
                    }  else if(s==502118) {
                        ewq[59] = r;
                    }  else if(s==502119) {
                        ewq[60] = r;
                    }  else if(s==502128) {
                        ewq[61] = r;
                    }  else if(s==502129) {
                        ewq[62] = r;
                    } else if(s==502130) {
                        ewq[63] = r;
                    }  else if(s==200164) {
                        ewq[64] = r;
                    }else if(s==502001) {
                        ewq[66] = r;
                    } else if(s==502002) {
                        ewq[67] = r;
                    } else if(s==502003) {
                        ewq[68] = r;
                    } else if(s==502004) {
                        ewq[69] = r;
                    } else if(s==502005) {
                        ewq[70] = r;
                    } else if(s==502006) {
                        ewq[71] = r;
                    } else if(s==502007) {
                        ewq[72] = r;
                    } else if(s==502008) {
                        ewq[73] = r;
                    } else if(s==502009) {
                        ewq[74] = r;
                    } else if(s==502010) {
                        ewq[75] = r;
                    } else if(s==502100) {
                        ewq[76] = r;
                    } else if(s==502101) {
                        ewq[77] = r;
                    } else if(s==502102) {
                        ewq[78] = r;
                    } else if(s==502103) {
                        ewq[79] = r;
                    } else if(s==502104) {
                        ewq[80] = r;
                    } else if(s==502105) {
                        ewq[81] = r;
                    }else if(s==502106) {
                        ewq[82] = r;
                    } else if(s==502107) {
                        ewq[83] = r;
                    } else if(s==502108) {
                        ewq[84] = r;
                    } else if(s==502109) {
                        ewq[85] = r;
                    } else if(s==502110) {
                        ewq[86] = r;
                    } else if(s==502111) {
                        ewq[87] = r;
                    } else if(s==502112) {
                        ewq[88] = r;
                    } else if(s==502113) {
                        ewq[89] = r;
                    } else if(s==502114) {
                        ewq[90] = r;
                    }else if(s==502201||s==502203){
                        ewq[91] += r;
                    }else if(s==502206||s==502208||s==502210||s==502212||s==502215){
                        ewq[92] += r;
                    }else if(s==502207||s==502209||s==502211||s==502213||s==502216){
                        ewq[93] += r;
                    }else if(s==502217||s==502219||s==502221||s==502223||s==502226){
                        ewq[94] += r;
                    }else if(s==502218||s==502220||s==502222||s==502224||s==502227){
                        ewq[95] += r;
                    }else if(s==502228||s==502230||s==502232||s==502234||s==502237){
                        ewq[96] += r;
                    }else if(s==502229||s==502231||s==502233||s==502235||s==502238){
                        ewq[97] += r;
                    }
                }}
              //  int qwe[]={ewq[0],ewq[1],ewq[2],ewq[3],ewq[4],ewq[5],ewq[6],ewq[7],ewq[8],ewq[9],ewq[10],ewq[11],ewq[12],ewq[13],ewq[14],ewq[15],ewq[16],ewq[17],ewq[18],ewq[19],ewq[20],ewq[21],ewq[22],ewq[23],ewq[24],ewq[25],ewq[26],ewq[27],ewq[28],ewq[29],ewq[30],ewq[31]};
                yDataMaps.put( (i+1)+"",ewq);
                Map map1=new HashMap();
                map1.put("id",list.get(i).getId());
                map1.put("time",list.get(i).getTime());
                map1.put("channel",list.get(i).getChannel());
                map1.put("theFather",list.get(i).getTheFather());
                map1.put("hasChildren",true);
                map1.put("theValues",ewq);
                list1.add(map1);
            }
        }
        Map map=new HashMap();
        map.put("chartData",yDataMaps);
        map.put("xData",xData);
        map.put("content",list1);
        map.put("totalElements",ipage.getTotal());
        map.put("countData",1);
        return map;

    }

    @Override
    public List<Map> getChargeBuyProps(Integer time,String channel){
        QueryWrapper<PropsInfoEntity> wrapper =new QueryWrapper<>();
        if(time!=null&&time>0){
            wrapper.eq("time",time);
            wrapper.eq("the_father",channel);
        }
        wrapper.orderBy(true,false,"id");
        List<PropsInfoEntity> list = propsInfoMapper.selectList(wrapper);
        List<Map> list1=new ArrayList();
        if(list.size()>0) {
            for (int i = 0; i < list.size(); i++) {
                String sad[]= list.get(i).getTheValues().split("/");
                int ewq[]=new int[98];
                for (int j=0;j<sad.length;j++){
                    int s=Integer.parseInt(sad[j].split("-")[0]) ;
                    int r=Integer.parseInt(sad[j].split("-")[1]);
                    if(s==500232) {
                        ewq[0] =r;
                    }
                    else if(s>=500261&&s<=500270) {
                        ewq[1] += r;
                    }
                    else if(s>=500241&&s<=500250) {
                        ewq[2] += r;
                    }
                    else if(s>=500251&&s<=500260) {
                        ewq[3] += r;
                    }else if(s==500296||s==500297||s==500335||s==500337||s==500339||s==500354||s==500355||s==500650||s==500655||s==500665||s==500675) {
                        ewq[4] += r;
                    }else if(s==500298||s==500299||s==500338||s==500340||s==500345||s==500359||s==500405||s==500651||s==500656||s==500666||s==500676) {
                        ewq[5] += r;
                    }else if(s==500300||s==500301||s==500341||s==500346||s==500356||s==500360||s==500406||s==500652||s==500657||s==500667||s==500677) {
                        ewq[6] += r;
                    }else if(s==500302||s==500303||s==500342||s==500347||s==500357||s==500361||s==500426||s==500653||s==500658||s==500668||s==500678) {
                        ewq[7] += r;
                    }else if(s==500304||s==500305||s==500343||s==500348||s==500358||s==500362||s==500427||s==500654||s==500659||s==500669||s==500679) {
                        ewq[8] += r;
                    }else if(s==500407||s==500411||s==500428||s==500333||s==500660||s==500670||s==500680||s==500755) {
                        ewq[9] += r;
                    }else if(s==500306||s==500307||s==500344||s==500349||s==500363||s==500429||s==500661||s==500671||s==500681||s==500756) {
                        ewq[10] += r;
                    }else if(s==500308||s==500309||s==500350||s==500364||s==500408||s==500662||s==500672||s==500682||s==500757) {
                        ewq[11] += r;
                    }else if(s==500310||s==500311||s==500351||s==500365||s==500409||s==500663||s==500673||s==500683||s==500758) {
                        ewq[12] += r;
                    }else if(s==500312||s==500352||s==500410||s==500664||s==500674||s==500684||s==500759) {
                        ewq[13] += r;
                    }else if(s==500320||s==500367||s==500369||s==500371||s==500685||s==500690||s==500700||s==500710) {
                        ewq[14] += r;
                    }else if(s==500321||s==500370||s==500372||s==500377||s==500412||s==500686||s==500691||s==500701||s==500711) {
                        ewq[15] += r;
                    }else if(s==500322||s==500373||s==500378||s==500413||s==500687||s==500692||s==500702||s==500712) {
                        ewq[16] += r;
                    }else if(s==500323||s==500374||s==500379||s==500430||s==500688||s==500693||s==500703||s==500713) {
                        ewq[17] += r;
                    }else if(s==500324||s==500375||s==500380||s==500431||s==500689||s==500694||s==500704||s==500714) {
                        ewq[18] += r;
                    }else if(s==500414||s==500418||s==500432||s==500695||s==500705||s==500715||s==500760) {
                        ewq[19] += r;
                    }else if(s==500325||s==500376||s==500381||s==500433||s==500696||s==500706||s==500716||s==500761) {
                        ewq[20] += r;
                    }else if(s==500326||s==500382||s==500415||s==500697||s==500707||s==500717||s==500762) {
                        ewq[21] += r;
                    }else if(s==500327||s==500383||s==500416||s==500698||s==500708||s==500718||s==500763) {
                        ewq[22] += r;
                    }else if(s==500328||s==500384||s==500417||s==500699||s==500709||s==500719||s==500764) {
                        ewq[23] += r;
                    }else if(s==500619||s==500623||s==500630||s==500640){
                        ewq[24] += r;
                    } else if(s==500620||s==500624||s==500631||s==500641){
                        ewq[25] += r;
                    }  else if(s==500621||s==500625||s==500632||s==500642){
                        ewq[26] += r;
                    }  else if(s==500622||s==500626||s==500633||s==500643){
                        ewq[27] += r;
                    }  else if(s==500627||s==500634||s==500644||s==500770){
                        ewq[28] += r;
                    }  else if(s==500628||s==500635||s==500645||s==500771){
                        ewq[29] += r;
                    }  else if(s==500629||s==500636||s==500646||s==500772){
                        ewq[30] += r;
                    }  else if(s==500637||s==500647||s==500773||s==500776){
                        ewq[31] += r;
                    }  else if(s==500638||s==500648||s==500774||s==500777){
                        ewq[32] += r;
                    }  else if(s==500639||s==500649||s==500775||s==500778){
                        ewq[33] += r;
                    } else if(s==500332){
                        ewq[34] = r;
                    }else if(s==501000){
                        ewq[65] =r ;
                    }
                    else if(s==200089||s==500292) {
                        ewq[35] += r;
                    } else if(s==200090||s==500293) {
                        ewq[36] += r;
                    } else if(s==200091||s==500294) {
                        ewq[37] += r;
                    }else if(s==200092||s==500295) {
                        ewq[38] += r;
                    }
                    else if(s==500216||s==500611) {
                        ewq[39] += r;
                    }
                    else if(s==500217||s==500612) {
                        ewq[40] += r;
                    }
                    else if(s==500218||s==500613) {
                        ewq[41] += r;
                    }
                    else if(s==500219||s==500614) {
                        ewq[42] += r;
                    }
                    else if(s==500271) {
                        ewq[43] = r;
                    }
                    else if(s==500272) {
                        ewq[44] = r;
                    }  else if(s==500273) {
                        ewq[45] = r;
                    }  else if(s==500274) {
                        ewq[46] = r;
                    }  else if(s==500275) {
                        ewq[47] = r;
                    }  else if(s==500276) {
                        ewq[48] = r;
                    }  else if(s==500277) {
                        ewq[49] = r;
                    }  else if(s==500278) {
                        ewq[50] = r;
                    }  else if(s==500279) {
                        ewq[51] = r;
                    }  else if(s==500331) {
                        ewq[52] = r;
                    } else if(s==500330) {
                        ewq[53] = r;
                    }
                    else if(s==200167) {
                        ewq[54] = r;
                    }
                    else if(s==200170) {
                        ewq[55] = r;
                    }  else if(s==200173) {
                        ewq[56] = r;
                    }  else if(s==200176) {
                        ewq[57] = r;
                    }  else if(s==200146) {
                        ewq[58] = r;
                    }  else if(s==200149) {
                        ewq[59] = r;
                    }  else if(s==200152) {
                        ewq[60] = r;
                    }  else if(s==200155) {
                        ewq[61] = r;
                    }  else if(s==200158) {
                        ewq[62] = r;
                    } else if(s==200161) {
                        ewq[63] = r;
                    }  else if(s==200164) {
                        ewq[64] = r;
                    }  else if(s==502001) {
                        ewq[66] = r;
                    } else if(s==502002) {
                        ewq[67] = r;
                    } else if(s==502003) {
                        ewq[68] = r;
                    } else if(s==502004) {
                        ewq[69] = r;
                    } else if(s==502005) {
                        ewq[70] = r;
                    } else if(s==502006) {
                        ewq[71] = r;
                    } else if(s==502007) {
                        ewq[72] = r;
                    } else if(s==502008) {
                        ewq[73] = r;
                    } else if(s==502009) {
                        ewq[74] = r;
                    } else if(s==502010) {
                        ewq[75] = r;
                    } else if(s==502100) {
                        ewq[76] = r;
                    } else if(s==502101) {
                        ewq[77] = r;
                    } else if(s==502102) {
                        ewq[78] = r;
                    } else if(s==502103) {
                        ewq[79] = r;
                    } else if(s==502104) {
                        ewq[80] = r;
                    } else if(s==502105) {
                        ewq[81] = r;
                    }else if(s==502106) {
                        ewq[82] = r;
                    } else if(s==502107) {
                        ewq[83] = r;
                    } else if(s==502108) {
                        ewq[84] = r;
                    } else if(s==502109) {
                        ewq[85] = r;
                    } else if(s==502110) {
                        ewq[86] = r;
                    } else if(s==502111) {
                        ewq[87] = r;
                    } else if(s==502112) {
                        ewq[88] = r;
                    } else if(s==502113) {
                        ewq[89] = r;
                    } else if(s==502114) {
                        ewq[90] = r;
                    }
                }
                 Map map1=new HashMap();
                map1.put("id",list.get(i).getId());
                map1.put("time",list.get(i).getTime());
                map1.put("channel",list.get(i).getChannel());
                if(list.get(i).getChannel().indexOf("_total")>0) {

                    map1.put("hasChildren", true);
                }else {
                    map1.put("hasChildren", false);
                }
                map1.put("theValues",ewq);
                list1.add(map1);
            }
        }
        return list1;
    }

    @Override
    public List<CardInfoEntity> propsCard(Integer time,String channel){
        System.out.println(time);
        QueryWrapper<CardInfoEntity> wrapper =new QueryWrapper<>();
        if(time!=null&&time>0){
            wrapper.eq("time",time);
            wrapper.eq("the_father",channel);
        }
        wrapper.orderBy(true,false,"id");
        List<CardInfoEntity> list = cardInfoMapper.selectList(wrapper);
        if(list.size()>0){
            for(CardInfoEntity cardInfoEntity:list){
                 if(cardInfoEntity.getChannel().indexOf("_total")>0){

                }else {
                     cardInfoEntity.setHasChildren(false);
                }
            }
        }
        return list;
    }
}
